//
//  KWTStationListCell.m
//  RuiHeApp
//
//  Created by Yan Chen on 2024/10/15.
//

#import "KWTStationListCell.h"
#import "RHPlantModel.h"
@interface KWTStationListCell()
@property(nonatomic,strong)UIImageView *selectIcon;

@property(nonatomic,strong)QMUILabel *deviceNameLab;

@property(nonatomic,strong)QMUILabel *deviceCountLab;

@property(nonatomic,strong)QMUILabel *statusLab;

@property(nonatomic,strong)UIImageView *deviceIcon;

@end
@implementation KWTStationListCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if(self){
        [self setupUI];
    }
    return self;
}
-(void)setModel:(RHPlantModel *)model
{
    _model = model;
    self.deviceNameLab.text = model.plantName;
    self.deviceCountLab.text = [NSString stringWithFormat:@"%ld",model.deviceAmount];
    self.selectIcon.image = [UIImage imageNamed:model.isSelected?@"ugrade_select":@"ugrade_cancel"];
    
}
- (void)setupUI{
    
    [self setBackgroundColor:UIColor.clearColor];
    [self.contentView setBackgroundColor:UIColor.clearColor];
    
    UIView *containView = [[UIView alloc]init];
    [self.contentView addSubview:containView];
    containView.backgroundColor = CFTabViewBgColor;
    containView.layer.cornerRadius = 8;
    containView.layer.masksToBounds = YES;
    
    _selectIcon = [[UIImageView alloc]init];
    _selectIcon.contentMode = UIViewContentModeScaleAspectFit;
    [_selectIcon setImage:[UIImage imageNamed:@"device_disSelected"]];
    [containView addSubview:_selectIcon];
    
    
    _deviceNameLab = [[QMUILabel alloc]init];
    [containView addSubview:_deviceNameLab];
    _deviceNameLab.font = [UIFont boldSystemFontOfSize:15];
    _deviceNameLab.text = @"User";
    _deviceNameLab.textAlignment = NSTextAlignmentLeft;
    _deviceNameLab.textColor = [UIColor colorWithHexString:@"3F4443"];

    
    QMUILabel *deviceCountTitleLab = [[QMUILabel alloc]init];
    [containView addSubview:deviceCountTitleLab];
    deviceCountTitleLab.font = [UIFont boldSystemFontOfSize:14];
    deviceCountTitleLab.text = [NSString stringWithFormat:@"%@:",@"设备数量".rh_localized];
    deviceCountTitleLab.textAlignment = NSTextAlignmentLeft;
    deviceCountTitleLab.textColor = [UIColor colorWithHexString:@"3F4443" alpha:0.6];
    
    _deviceCountLab = [[QMUILabel alloc]init];
    [containView addSubview:_deviceCountLab];
    _deviceCountLab.font = [UIFont boldSystemFontOfSize:14];
    _deviceCountLab.text = @"--";
    _deviceCountLab.textAlignment = NSTextAlignmentLeft;
    _deviceCountLab.textColor = [UIColor colorWithHexString:@"3F4443" alpha:0.6];
   
    
    
    kWeakSelf;
    _deviceIcon = [[UIImageView alloc]init];
    _deviceIcon.contentMode = UIViewContentModeScaleAspectFit;
    [containView addSubview:_deviceIcon];
    [_deviceIcon setImage:[UIImage imageNamed:@"station_icon"]];
    
    _statusLab = [[QMUILabel alloc]init];
    [containView addSubview:_statusLab];
    _statusLab.font = [UIFont boldSystemFontOfSize:12];
    _statusLab.text = @"--";
    _statusLab.textAlignment = NSTextAlignmentLeft;
    _statusLab.textColor = [UIColor colorWithHexString:@"3F4443" alpha:0.6];
    _statusLab.hidden = YES;
    [containView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.edges.insets(UIEdgeInsetsMake(5, 15, 5, 15));
    }];
    
    [_selectIcon mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.offset(-15);
            make.width.height.offset(kScaleW(18));
            make.centerY.mas_offset(0);
    }];
    
    [_deviceIcon mas_makeConstraints:^(MASConstraintMaker *make) {
            make.width.height.offset(kScaleW(30));
            make.left.mas_offset(15);
            make.centerY.mas_offset(0);
    }];
    
    [_deviceNameLab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(weakSelf.deviceIcon.mas_right).offset(10);
            make.right.equalTo(weakSelf.selectIcon.mas_left).offset(-10);
            make.top.mas_offset(15);
//            make.height.offset(25);
    }];
    
    [deviceCountTitleLab sizeToFit];
    [deviceCountTitleLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.deviceNameLab);
        make.top.equalTo(weakSelf.deviceNameLab.mas_bottom).offset(5);
        make.bottom.mas_offset(-15);
        make.width.offset(deviceCountTitleLab.width+1);
    }];
    
    [_deviceCountLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(deviceCountTitleLab.mas_right).offset(3);
        make.centerY.equalTo(deviceCountTitleLab);
        make.right.mas_offset(-5);
    }];
    
   
    
    [_statusLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_offset(-5);
        make.centerX.equalTo(weakSelf.deviceIcon);
    }];
}

@end
